package com.tanhua.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.tanhua.dubbo.mapper.UserMapper;
import com.tanhua.model.domain.User;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @author LiKe
 * @date 2022/1/20 17:55
 */
@DubboService
public class UserApiImpl implements UserApi {
    @Autowired
    private UserMapper userMapper;
    @Override
    public User findByMobile(String mobile) {
        LambdaQueryWrapper<User> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(User::getMobile,mobile);
        return userMapper.selectOne(queryWrapper);
    }

    @Override
    public Long save(User user) {
        userMapper.insert(user);
        return user.getId();
    }

    @Override
    public void updatePhone(Long userId, String phone) {
        User user = new User();
        user.setId(userId);
        user.setMobile(phone);
        userMapper.updateById(user);
    }

    @Override
    public User findByid(Long userId) {
        User user = userMapper.selectById(userId);

        return user;
    }

    @Override
    public void update(User user) {
        userMapper.updateById(user);
    }
    @Override
    public List<User> findAllUser() {

        List<User> list = userMapper.selectList(Wrappers.emptyWrapper());
        return list;
    }

    @Override
    public User findByHxId(String huanxinId) {
        LambdaQueryWrapper<User> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(User::getHxUser,huanxinId);
        return userMapper.selectOne(queryWrapper);
    }
}
